home *** CD-ROM | disk | FTP | other *** search
- #include "stdio.h"
-
- struct complex
- {
- double real, imag;
- };
-
- struct complex cplx_add(struct complex * a, struct complex * b);
- int cplx_print(struct complex * c);
-
- int main()
- {
- struct complex c1, c2, c3;
-
- c1.real = 1.5;
- c1.imag = 0.0;
-
- c2.real = 7.1;
- c2.imag = 8.0;
-
- c3 = cplx_add(&c1,&c2);
-
- cplx_print(&c3);
-
- return 0;
- }
-
- struct complex cplx_add(struct complex * a, struct complex * b)
- {
- struct complex result;
-
- result.real = a->real + b->real;
- result.imag = a->imag + b->imag;
-
- return result;
- }
-
- int cplx_print(struct complex * c)
- {
- return printf("(%g%+gi)",c->real,c->imag);
- }
-